Programming in C by Munishwar Gulati & Mini Gulati
Author:Munishwar Gulati & Mini Gulati [Gulati, Munishwar]
Language: eng
Format: epub
Published: 2016-11-30T08:00:00+00:00
POINTERS
POINTERS AND ARRAYS
DYNAMIC MEMORY ALLOCATION
STRING POINTER
POINTERS AND FUNCTIONS
POINTER TO A FUNCTION
140
Chapter 6 : Pointers
POINTERS
The variables are stored in memory at specific locations. These
location have the addresses. When the name of the variable is used,
it translate the name into the addresses. The procedure is automatic
and need no concern of the programmer.
The memory addresses can be used because of the fact that memory
addresses are global to all functions, whereas local variable names
are meaningful only within the functions in which they are declared.
A function can pass the address of local variable to another functions,
and the second function can use this address to access the contents
of the first function’s local variables.
The computer’s memory is a sequential collection of storage cells.
Each cell, commonly known as byte has a number called address
associated with it. Typically, the addresses are numbered
consecutively, starting from zero. The last address depends on the
memory size. A computer system having 64K memory will have its
last address as 65,535.
Whenever a variable is declared, the system allocates it somewhere in
the memory at an appropriate location to hold the value of the
variable. Since every byte has a unique address number, this
location will also have its own address number.
Consider the following variable
int addr = 15;
This statement will store the variable addr at some location and will
but value 15 is that location. Let us assume the address of the
location as 2001.
During execution of the program, the system always associates the
name addr with the address 2001. The value 15 can be accessed by
using either the variable name addr or the address 2001.
Since memory address are simply numbers, they can be assigned to
some variables which can be stored in memory, like any other
variable. Such variable that hold memory addresses are called
pointers. A pointer is, therefore, nothing but a variable that contains
an address which is a location of another variable in memory.
It must be noted down, that since a pointer is a variable, its value is
also stored in the memory in another variable in memory at some
other location. Let us assign the address of quantity to a variable ad.
The links between variable ad and addr can be shown as
ad
2001
15
addr
Chapter 6 : Pointers
141
Since the value of ad is address of the variable addr, therefore, it may
be said that the variable ad points to the variable addr. Thus ad gets
the name pointer.
THE ADDRESS OPERATOR
The actual location of a variable, where it is stored, called address of
the variable, is system dependent. Addresses are a sperate data type
in C, distinct from other types introduced so far. The address of a
variable is not known to us immediately.
The ampersand (&) immediately preceding a variable name in a call
to the scanf function returns the address of the variable associated
with it. The operator is known as address operator and it is not
restricted to scanf function. It can be used with any variable name or
array element, but not the constant, to know the address of variable
ar array element respectively.
e.g.
p = &addr;
The above statement would result in p = 2001 as addr has been stored
at the address number 2001.
e.g.
main ()
{
char grade;
int
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(26908)
Hello! Python by Anthony Briggs(25784)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(25102)
Kotlin in Action by Dmitry Jemerov(24206)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(23430)
Dependency Injection in .NET by Mark Seemann(23163)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(21821)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(20713)
Grails in Action by Glen Smith Peter Ledbrook(19736)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17057)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(16732)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(14383)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(12498)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11799)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10645)
Hit Refresh by Satya Nadella(9223)
The Kubernetes Operator Framework Book by Michael Dame(8580)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8432)
Robo-Advisor with Python by Aki Ranin(8376)